const express = require('express')
const app = express()
var ws_1 = require("ws");
// 定义websocket服务器
var wsServer = new ws_1.Server({ port: 8085 });
// 定义连接到的websocket集合
var socketSet = new Set();
// 连接
wsServer.on('connection', function (websocket) {
    socketSet.add(websocket);
});
// 初始化消息数
var message = 0;
// 定时2s发送消息
setInterval(function () {
    socketSet.forEach(function (ws) {
        if (ws.readyState == 1) {
            ws.send(JSON.stringify({
                message: message++
            }));
        }
        else {
            socketSet["delete"](ws);
        }
    });
}, 2000);

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(3000, () => console.log('Example app listening on port 3000!'))